<extend name="Public:base" />
<block name="title">食堂档口管理</block>
<block name="content">
    
    <div class=" ace-save-state" id="breadcrumbs">
        <div class="page-header">
            <h1>食堂档口管理
                <small><i class="ace-icon fa fa-angle-double-right"></i><a href="{:U('Admin/Window/index')}">食堂管理</a></small>
                <small><i class="ace-icon fa fa-angle-double-right"></i>全部食堂</small>
            </h1>
        </div>
    
        
        <!-- /.ace-settings-container -->
        <div class="page-content">
            
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <div class="col-xs-12">
                            <table id="simple-table" class="table  table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="center">食堂名称</th>
                                    <th class="detail-col center">档口数量</th>
                                    <th class="center">联系人</th>
                                    <th class="hidden-480 center">联系电话</th>
                                    <th>
                                        <button type="button" class="btn btn-sm btn-success" onclick="addCanteen()">
                                            <span>添加食堂</span>
                                        </button>
                                    </th>
                                </tr>
                                </thead>
                                
                                <tbody>
                                <?php foreach($canteenList as $k=>$l){?>
                                <tr>
                                    <td class="center"><?php echo $l['canteen_name'];?></td>
                                    <td class="center">0</td>
                                    <td class="center"><?php echo $l['canteen_contact_name'];?></td>
                                    <td class="hidden-480 center"><?php echo $l['canteen_contact_phone'];?></td>
                                    <td>
                                        <button type="button" class="btn btn-minier btn-purple" onclick="editCanteen(<?php echo $l['canteen_id']?>,1)">
                                            <span>修改信息</span>
                                        </button>
                                        <button type="button" class="btn btn-minier btn-warning" onclick="manageCanteen(<?php echo $l['canteen_id']?>   )">
                                            <span>管理档口</span>
                                        </button>
                                        <button type="button" class="btn btn-minier btn-danger" onclick="delCanteen(<?php echo $l['canteen_id']?>)">
                                            <span>删除食堂</span>
                                        </button>
                                    </td>
                                </tr>
                                <?php }?>
                                </tbody>
                            </table>
                        </div><!-- /.span -->
                    </div><!-- /.row -->
                    
                    
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div>
    </div>
    <div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                    <h4 class="modal-title" id="myModalLabel"> 添加食堂</h4></div>
                <div class="modal-body">
                    <form id="bjy-form" class="form-inline" action="{:U('Admin/Nav/add')}" method="post">
                        <input type="hidden" name="pid" value="0">
                        <table class="table table-striped table-bordered table-hover table-condensed">
                            <tr>
                                <th width="20%">食堂名称：</th>
                                <td><input class="input-medium" type="text" id="canteen_name"></td>
                            </tr>
                            <tr>
                                <th width="20%">联系人：</th>
                                <td><input class="input-medium" type="text" id="canteen_contact_name"></td>
                            </tr>
                            <tr>
                                <th width="20%">联系电话：</th>
                                <td><input class="input-medium" type="text" id="canteen_contact_phone"></td>
                            </tr>
                            <tr>
                                <th></th>
                                <td><input onclick="saveCanteen()" class="btn btn-success" type="button" value="添加">
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                    <h4 class="modal-title" id="myModalLabel2"> 编辑食堂</h4></div>
                <div class="modal-body">
                    <form id="bjy-edit-form" class="form-inline" action="{:U('Admin/Nav/add')}" method="post">
                        <input type="hidden" name="" id="canteen_id">
                        <table class="table table-striped table-bordered table-hover table-condensed">
                            <tr>
                                <th width="20%">食堂名称：</th>
                                <td><input class="input-medium" type="text" id="canteen_name2"></td>
                            </tr>
                            <tr>
                                <th width="20%">联系人：</th>
                                <td><input class="input-medium" type="text" id="canteen_contact_name2"></td>
                            </tr>
                            <tr>
                                <th width="20%">联系电话：</th>
                                <td><input class="input-medium" type="text" id="canteen_contact_phone2"></td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input onclick="saveEditCanteen()" class="btn btn-success" type="button" value="保存">
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        function saveEditCanteen(canteen_id, type) {
            var canteen_id = $("#canteen_id").val()
            var canteen_name = $("#canteen_name2").val()
            var canteen_contact_name2 = $("#canteen_contact_name2").val()
            var canteen_contact_phone2 = $("#canteen_contact_phone2").val()
            if (!canteen_name) {
                alert("请输入饭堂名称")
                return false
            }
            if (!canteen_contact_name2) {
                alert("请输入饭堂联系人")
                return false
            }
            if (!canteen_name) {
                alert("请输入饭堂联系电话")
                return false
            }
            var data = AjaxPost('/Admin/Window/editCanteen', {
                canteen_id: canteen_id,
                canteen_name: canteen_name,
                canteen_contact_name: canteen_contact_name2,
                canteen_contact_phone: canteen_contact_phone2
            })
            if (data.status == true) {
                alert("保存成功")
                window.location.reload()
            } else {
                alert("操作失败，请联系管理员")
            }
        }

        function editCanteen(canteen_id, type) {
            var data = AjaxGet('/Admin/Window/editCanteen', {
                canteen_id: canteen_id
            })
            $("#canteen_name2").val(data.data.canteen_name)
            $("#canteen_contact_name2").val(data.data.canteen_contact_name)
            $("#canteen_contact_phone2").val(data.data.canteen_contact_phone)
            $("#canteen_id").val(canteen_id)
            $('#bjy-edit').modal('show');

        }

        function manageCanteen(canteen_id) {
            window.location.href="{:U('/Admin/Window/WindowList/canteen_id/')}"+"/"+canteen_id
        }

        function delCanteen(canteen_id) {
            var flag = confirm("删除食堂后食堂下面的档口账号将全部失效，是否继续？")
            if (flag == true) {
                var data = AjaxPost('/Admin/Window/delCanteen', {
                    canteen_id: canteen_id
                })
                if (data.status == true) {
                    alert("删除成功")
                    window.location.reload()
                } else {
                    alert("操作失败，请联系管理员")
                }

            }

        }

        function addCanteen() {
            $('#bjy-add').modal('show');
        }

        function saveCanteen() {
            var canteen_name = $("#canteen_name").val()
            var canteen_contact_name = $("#canteen_contact_name").val()
            var canteen_contact_phone = $("#canteen_contact_phone").val()
            if (!canteen_name) {
                alert("请填写正确的食堂名称")
                return false
            }
            if (!canteen_contact_name) {
                alert("请填写食堂联系人")
                return false
            }
            if (!canteen_contact_phone) {
                alert("请填写食堂联系电话")
                return false
            }
            var data = AjaxPost("/Admin/Window/addCanteen", {
                canteen_name: canteen_name,
                canteen_contact_name: canteen_contact_name,
                canteen_contact_phone: canteen_contact_phone
            })
            if (data.status == true) {
                alert('添加成功')
                window.location.reload()
            } else {
                alert(data.message)
            }


        }
    </script>
</block>
<block name="js"></block>
